#pragma once

#include "PanView.h"
#include "ZoomTool.h"
#include "typelib/types.h"

class ZoomView : public PanView
{
	friend class ZoomTool;
	typedef PanView Base;

public:
	ZoomView(); 
	virtual ~ZoomView();

// Attributes
protected:

	extent<float>	m_BenchSize;
	float			m_Scale;
	mutable ZoomTool		m_ToolZoom;	 

protected:  

	float			m_MinScale;
	float			m_MaxScale;

	bool			m_YUp;

	virtual void OnScale() { }
	virtual void UpdateAltTool();

public:

	ZoomTool * GetZoomTool() const
		{ return &m_ToolZoom; }

	float GetScale() const
		{ return m_Scale; }

	float GetMinScale() const
		{ return m_MinScale; }
	float GetMaxScale() const
		{ return m_MaxScale; }

	extent<float> GetBenchSize() const
		{ return m_BenchSize; }

	CPoint Center();

	void Zoom(float scale, CPoint * p = 0);
	void ZoomBy(float factor, CPoint * p = 0);
	void ZoomFit();

// Operations
public:

	point<float> ClientToBench(CPoint p) const;
	CPoint BenchToClient(point<float> p) const;

	rect<float> ClientToBench(CRect r) const;
	CRect BenchToClient(rect<float> r) const;
	CRect BenchToClient(CRect r) const;
	rect<float> BenchToClient2(rect<float> r) const;

	///converts Client rectangle into Bench one, 
	///extending the former to obtain maximally whole numbers, but extending no more than on e
	void BestWholeMapping(CRect & c, CRect & b, unsigned e = 100) const;

	void Superpose(point<float> bench, CPoint client);

	void SetScale(float scale);

	void ResizeBench(extent<float> s);
	void ResizeBench(float sx, float sy)
		{ ResizeBench(extent<float>(sx, sy)); }

	void UpdateBenchSize();

	//parameters description see in help for CreateEnhMetaFile(...) function
	//scale=100 => 1px = 1mm
	void CreateEnhMetaFile(LPCTSTR lpFilename, LPCTSTR lpDescription = 0, float scale = 100);

protected:
	DECLARE_MESSAGE_MAP()
	afx_msg void OnZoomTool();
	afx_msg void OnUpdateZoomTool(CCmdUI *pCmdUI);
	afx_msg void OnZoomIn();
	afx_msg void OnUpdateZoomIn(CCmdUI* pCmdUI);
	afx_msg void OnZoomOut();
	afx_msg void OnUpdateZoomOut(CCmdUI* pCmdUI);
	afx_msg void OnFitOnScreen();
	afx_msg void OnUpdateFitOnScreen(CCmdUI* pCmdUI);
	afx_msg void OnActualPixels();
	afx_msg void OnUpdateActualPixels(CCmdUI* pCmdUI);
	afx_msg void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnSysKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
